﻿
#include "DlgRunFindSubNets.h"
#include <vtkArcSource.h>
#include <vtkActor.h>    
#include <vtkPolyDataMapper.h>    



DlgRunFindSubNets::DlgRunFindSubNets(QWidget* parent):
    DlgBase(parent)
{
    initUI();
    manageConnections();
}

DlgRunFindSubNets::~DlgRunFindSubNets()
{
}

bool DlgRunFindSubNets::RunTool()
{
    /*   auto pVtkViewWindow = MyVtkViewWindow::GetInstance();
       if( pVtkViewWindow == nullptr )
       {
           return false;
       }*/

       //get info from UI
    QString strNetInfo = m_pNetInfoEdit->text();
    if( strNetInfo.isEmpty() )
    {
        return false;
    }



    switch( m_toolType )
    {
    case E_JS_FINDER:
        {
            m_pJSFinderNum->setValue(10);
            break;
        }

    case E_ONE_FOR_ALL:
        {
            m_pOneForAllNum->setValue(15);
            break;
        }
    }

    return true;
}

void DlgRunFindSubNets::initUI()
{
    setWindowTitle("Find sub ntets");
    QVBoxLayout* pDlgLayout = new QVBoxLayout(this);  //create layout

    {
        m_pToolSelecComboBox = new QComboBox(this);
        m_pToolSelecComboBox->addItem(m_toolSelectBoxTexMap[E_JS_FINDER], E_JS_FINDER);
        m_pToolSelecComboBox->addItem(m_toolSelectBoxTexMap[E_ONE_FOR_ALL], E_ONE_FOR_ALL);
        m_pToolSelecComboBox->setCurrentText(m_toolSelectBoxTexMap[m_toolType]);
        pDlgLayout->addWidget(m_pToolSelecComboBox);

        m_pNetInfoEdit = new QLineEdit(this);
        pDlgLayout->addWidget(m_pNetInfoEdit);

        m_pJSFinderNum = new MyDoubleEdit(this, "JS Finder Num = ", 0, 0, INT_MAX, 0);
        pDlgLayout->addWidget(m_pJSFinderNum);

        m_pOneForAllNum = new MyDoubleEdit(this, "One For All Num = ", 0, 0, INT_MAX, 0);
        pDlgLayout->addWidget(m_pOneForAllNum);
        resetToolUI();
    }

    {
        m_pOkBtn = new QPushButton("OK", this);
        m_pCancelBtn = new QPushButton("Cancel", this);

        QHBoxLayout* okCancelLayout = new QHBoxLayout(this);
        okCancelLayout->addWidget(m_pOkBtn);
        okCancelLayout->addWidget(m_pCancelBtn);
        pDlgLayout->addLayout(okCancelLayout);
    }

    this->setLayout(pDlgLayout);
}

void DlgRunFindSubNets::manageConnections()
{
    connect(m_pToolSelecComboBox, &QComboBox::currentTextChanged, this, [=]()
    {
        resetToolUI();
    });

    connect(m_pOkBtn, &QPushButton::clicked, this, [=]()
    {
        bool bRunSuccess = RunTool();

        if( !bRunSuccess )
        {
            QMessageBox::warning(this, "Error", "Failed run" + m_toolSelectBoxTexMap[m_toolType] + "!");
        }
    });

    connect(m_pCancelBtn, &QPushButton::clicked, this, &DlgRunFindSubNets::close);
}

void DlgRunFindSubNets::resetToolUI()
{
    //reset UI for different tool
    m_pNetInfoEdit->setText("");
    m_pJSFinderNum->hide();
    m_pOneForAllNum->hide();

    m_toolType = m_pToolSelecComboBox->currentData().toInt();
    switch( m_toolType )
    {
    case E_JS_FINDER:
        {
            m_pJSFinderNum->setValue(0);
            m_pJSFinderNum->show();
            break;
        }

    case E_ONE_FOR_ALL:
        {
            m_pOneForAllNum->setValue(0);
            m_pOneForAllNum->show();
            break;
        }
    }
}


